﻿/// <summary>
/// 画柱状报表
/// </summary>
/// <param name="container">报表容器</param>
/// <param name="categories">X轴分类值</param>
/// <param name="colorData">颜色集合</param>
/// <param name="seriesData">数据列表</param>
/// <param name="maxY">Y轴最大值</param>
/// <param name="mainTitle">主标题</param>
/// <param name="subTitle">副标题</param>
/// <param name="xTitle">X轴名称</param>
/// <param name="yTitle">Y轴名称</param>
/// <returns></returns>
function drawChart(container,categories, colorData, seriesData, maxY, mainTitle, subTitle, xTitle, yTitle) {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: container,
            type: 'column'
        },
        credits:
        {
            enabled: false
        },
        title: {
            text: mainTitle,
            style: { color: '#000000', fontSize: '18px', fontFamily: '宋体', fontWeight: 'bolder' }
        },
        subtitle:
        {
            text: subTitle,
            style: { color: '#293955', fontSize: '12px', fontFamily: '宋体' },
            align: 'right'
        },
        xAxis: {
            title: {
                text: xTitle
            },
            categories: categories,
            labels: {
                style: { fontSize: '12px' }
            }
        },
        yAxis: {
            title: {
                text: yTitle
            },
            max: maxY
        },
        plotOptions: {
            column: {
                dataLabels: {
                    enabled: true,
                    color: colorData[0],
                    style: {
                        fontWeight: 'bold'
                    },
                    formatter: function () {
                        return this.y;
                    }
                }
            }
        },
        tooltip: {
            enabled: false
        },
        series: seriesData,
        legend: {
            layout: 'vertical',
            align: 'left',
            verticalAlign: 'bottom',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        exporting: {
            enabled: false
        }
    });
}



/// <summary>
/// 画线状报表
/// </summary>
/// <param name="container">报表容器</param>
/// <param name="categories">X轴分类值</param>
/// <param name="colorData">颜色集合</param>
/// <param name="seriesData">数据列表</param>
/// <param name="maxY">Y轴最大值</param>
/// <param name="mainTitle">主标题</param>
/// <param name="subTitle">副标题</param>
/// <param name="xTitle">X轴名称</param>
/// <param name="yTitle">Y轴名称</param>
/// <returns></returns>
function drawLineChart(container, categories, colorData, seriesData, maxY, mainTitle, subTitle, xTitle, yTitle) {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: container,
            type: 'line'
        },
        credits:
        {
            enabled: false
        },
        title: {
            text: mainTitle,
            style: { color: '#000000', fontSize: '18px', fontFamily: '宋体', fontWeight: 'bolder' }
        },
        subtitle:
        {
            text: subTitle,
            style: { color: '#293955', fontSize: '12px', fontFamily: '宋体' },
            align: 'right'
        },
        xAxis: {
            title: {
                text: xTitle
            },
            categories: categories,
            labels: {
                style: { fontSize: '12px' }
            }
        },
        yAxis: {
            title: {
                text: yTitle
            },
            max: maxY,
            min:0
        },
        plotOptions: {
            column: {
                dataLabels: {
                    enabled: true,
                    color: colorData[0],
                    style: {
                        fontWeight: 'bold'
                    },
                    formatter: function () {
                        return this.y;
                    }
                }
            }
        },
        tooltip: {
            formatter: function () {
                return '<b>' + this.series.name + '</b><br/>' +
                        this.x + ': ' + this.y + '个';
            }
        },
        series: seriesData,
        legend: {
            layout: 'vertical',
            align: 'left',
            verticalAlign: 'bottom',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        exporting: {
            enabled: false
        }
    });
}



/// <summary>
/// 画饼状报表
/// </summary>
/// <param name="container">报表容器</param>
/// <param name="seriesData">数据列表</param>
/// <param name="maxY">Y轴最大值</param>
/// <param name="mainTitle">主标题</param>
/// <param name="subTitle">副标题</param>
/// <returns></returns>
function drawPieChart(container, seriesData, mainTitle, subTitle) {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: container,
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        credits:
        {
            enabled: false
        },
        title: {
            text: mainTitle,
            style: { color: '#000000', fontSize: '18px', fontFamily: '宋体', fontWeight: 'bolder' }
        },
        subtitle:
        {
            text: subTitle,
            style: { color: '#293955', fontSize: '12px', fontFamily: '宋体' },
            align: 'right'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    style: { fontSize: '12px', fontFamily: '宋体' },
                    formatter: function () {
                        return '' + this.point.name + '：<b>' + this.point.y + '</b>';
                    }
                }
            }
        },
        tooltip: {
            pointFormat: '<b>{series.name}: {point.percentage}%</b>',
            percentageDecimals: 1
        },
        series: seriesData,
        exporting: {
            enabled: false
        }
    });
}




/// <summary>
/// 获取Y轴的最大值
/// </summary>
/// <param name="seriesData">数据列表</param>
/// <returns></returns>
function getMaxY(seriesData) {
    for (i = 0; i < seriesData.length; i++) {
        for (j = 0; j < seriesData[i].data.length; j++) {
            if (i == 0 && j == 0) {
                maxY = seriesData[i].data[j].y;
            }
            else {
                var tempValue = parseFloat(seriesData[i].data[j].y);
                if (tempValue > parseFloat(maxY)) {
                    maxY = tempValue;
                }
            }
        }
    }
    return maxY;
}